/**
 * 把奇数位和偶数位的节点排在一起，要求空间复杂度O(1) 时间复杂度O(n)
 * example: 1->2->3->4->5
 * return:  1->3->5->2->4
 * @param {ListNode} head 
 * 双指针
 */
var oddEvenList = function (head) {
    // 边界情况
    if (head === null) {
        return null
    }
    if (head.next === null) {
        return head
    }

    let odd = head
    let even = head.next
    // 保存偶数的第一位
    let evenHead = head.next

    while (even !== null && even.next !== null) {
        odd.next = odd.next.next
        odd = odd.next
        even.next = even.next.next
        even = even.next
    }
    odd.next = evenHead
    
    return head
}